import type { ComponentDefinition, ComponentType } from '@/types/component'
import { ref } from 'vue'

// 组件注册表
const componentRegistry = ref<Map<ComponentType, ComponentDefinition>>(new Map())

// 注册组件
export function registerComponent(component: ComponentDefinition) {
  componentRegistry.value.set(component.type, component)
}

// 获取组件
export function getComponentByType(type: ComponentType): ComponentDefinition | undefined {
  return componentRegistry.value.get(type)
}

// 获取组件配置
export function getComponentConfig(type: ComponentType): ComponentDefinition | undefined {
  return getComponentByType(type)
}

// 获取所有注册的组件
export function getRegisteredComponents(): ComponentDefinition[] {
  return Array.from(componentRegistry.value.values())
} 